package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.briup.jz.bean.Address;
import com.briup.jz.service.IAddressService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="顾客地址相关接口")
@Validated
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @ApiOperation(value = "查询顾客地址相关信息")
    @GetMapping("query")
    @ApiImplicitParams({
        @ApiImplicitParam(name="name",value = "收件人",paramType = "query"),
    })
    public Message query(String name){
        List<Address> list = addressService.query(name);
        return MessageUtil.success(list);
    }


    //分页查询
    @ApiOperation(value = "分页查询顾客地址相关信息")//注解依附于方法、属性...，需要在方法之上
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value = "当前页",paramType = "query",required = true),
            @ApiImplicitParam(name="pageSize",value = "每页大小",paramType = "query",required = true),
            @ApiImplicitParam(name="userId",value = "用户编号",paramType = "query"),
    })
    @GetMapping("pageQuery")
    public Message pageQuery(int page,int pageSize,Long userId){
        List<Address> list = addressService.pageQuery(page,pageSize,userId);
        return MessageUtil.success(list);
    }
    
    
    @ApiOperation(value = "通过id删除顾客信息")
    @DeleteMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
        addressService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新顾客信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
//            @ApiImplicitParam(name="name",value = "栏目名称",paramType = "form",required = true),
//            @ApiImplicitParam(name="description",value = "栏目描述",paramType = "form"),
//            @ApiImplicitParam(name="no",value = "序号",paramType = "form"),
//            @ApiImplicitParam(name="parentId",value = "父栏目id",paramType = "form"),
//    })
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form",required = true),
            @ApiImplicitParam(name="name",value = "收件人",paramType = "form"),
            @ApiImplicitParam(name="telephone",value = "手机号",paramType = "form"),
            @ApiImplicitParam(name="province",value = "省份",paramType = "form"),
            @ApiImplicitParam(name="city",value = "城市",paramType = "form"),
            @ApiImplicitParam(name="area",value = "区",paramType = "form"),
            @ApiImplicitParam(name="address",value = "详细地址",paramType = "form"),
            @ApiImplicitParam(name="isDefault",value = "是否默认",paramType = "form"),
            @ApiImplicitParam(name="userId",value = "用户编号",paramType = "form"),

    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Address address){
        addressService.saveOrUpdate(address);
        return MessageUtil.success("更新成功");
    }
}

